Skip to content

Comments

Fix NoSuchElementException for listeners with inferred types#669

Merged
LakshanWeerasinghe merged 4 commits intoballerina-platform:1.6.xfrom
pasindufernando1:1887Fix
Feb 2, 2026
Merged

Fix NoSuchElementException for listeners with inferred types#669
LakshanWeerasinghe merged 4 commits intoballerina-platform:1.6.xfrom
pasindufernando1:1887Fix

Conversation

@pasindufernando1
Copy link
Contributor

@pasindufernando1 pasindufernando1 commented Feb 2, 2026

Purpose

This PR handles cases of NoSuchElementExceptions in CodeAnalyzer.visit(ListenerDeclarationNode) when processing listener declarations without explicit type descriptors (e.g., listener list = new http:Listener(8080)). The code now handles both explicit type declarations and type-inferred listeners by extracting the type from the ExplicitNewExpressionNode initializer when no type descriptor is present.

Fixes : wso2/product-ballerina-integrator#1887

Screen.Recording.2026-02-02.at.13.00.55.mov

Copilot AI review requested due to automatic review settings February 2, 2026 07:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a NoSuchElementException that occurs when processing listener declarations without explicit type descriptors (e.g., listener list = new http:Listener(8080)). The fix properly handles type inference by checking if a type descriptor is present before accessing it, and extracting the type from the ExplicitNewExpressionNode initializer when needed.

Changes:

  • Added logic to handle three cases for listener type extraction: explicit type descriptors, type inferred from ExplicitNewExpressionNode, and fallback to semantic model type inference
  • Added test case with a listener declaration using type inference to validate the fix

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
CodeAnalyzer.java Fixed NoSuchElementException by checking typeDescriptor presence before calling get(), and added logic to extract type from ExplicitNewExpressionNode initializer for inferred types
project_8/main.bal Test case demonstrating listener with inferred type syntax
project_8/Ballerina.toml Test project configuration
project_with_only_listener.json Expected test output for the inferred-type listener test case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@LakshanWeerasinghe LakshanWeerasinghe merged commit 9461c19 into ballerina-platform:1.6.x Feb 2, 2026
3 checks passed
@NipunaRanasinghe
Copy link
Contributor

@pasindufernando1 can you please attach the related GH issue in the PR description?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants